package leetcode.sort;

//23,46,0,8,11,18
//2,1,3
public class QuickSort {
    public static void main(String[] args) {
        int[] nums = {23,46,0,8,11,18,9};
        sort(nums,0,nums.length-1);
        for (int i = 0; i < nums.length; i++) {
            System.out.println(nums[i]);
        }
    }

    public static void sort(int[] nums, int start, int end) {
        if (start>=end){
            return;
        }
        int temp = nums[start];
        int left = start, right = end;

        while (left < right) {
            while (nums[right] >= temp && left < right) {
                right--;
            }
            while (nums[left] <= temp && left <right) {
                left++;
            }
            if (left < right) {
                nums[left] = nums[left] ^ nums[right];
                nums[right] = nums[left] ^ nums[right];
                nums[left] = nums[left] ^ nums[right];
            }
        }
                nums[start] = nums[right];
                nums[right] = temp;
                sort(nums,0,right-1);
                sort(nums,right+1,end);
    }
}
